<?php
ob_start();
session_start();

if((isset($_POST['email'])) && (isset($_POST['password']))){
    

   $email= $_POST['email'];
   $pass= $_POST['password'];
   
   try{
         include_once('restconnection.php');
         
         if(isset($client)){
            
            //retrive base url 
            $url = $_SESSION['basic_url'];
            //add service url
            $service_url="/LoginCompany?";
            //params url
            $params = array('email'=>$email, 'password'=>$pass);
            //params connection
            $ctx = stream_context_create(array('http' => array('timeout' => 30))); 
            //send GET reques
            $output = @file_get_contents($url.$service_url."email=".$params['email']."&"."password=".$params['password'],0,$ctx);
            //parse JSON output
            $data = json_decode($output);
            $id = $data->LoginCompanyResult;
            
         
            if($id != "0"){
                
                 //echo$id;
                 $_SESSION['id']=$id;      
                 $_SESSION['email']=$email;
                 $_SESSION['password']=$pass;
                 //unset($_SESSION['loginerror']);
                 
                 header("Location: home.php");
       
             }else{
                 
                 //$_SESSION['loginerror']=1;
                 header("Location: login_page.php?loginerror=1");  
            }
            
         }else{ 
          //$_SESSION['loginerror']=2; 
          header("Location: login_page.php");     
             
         }

    }  catch (Exception $e){
       
      ?>
          <label style="color:red;font-size:15px;">Sorry Connection Error!</label><br/>
          <label><a><element onclick=" var link='esa/login_page.php'; ovv_mainother(link);" > Click to continue </a></label>
          
      <?php    
       
   }  
     
}

?>

          
